package tool

import (
	"context"
	"github.com/gin-gonic/gin"
	log "go-micro.dev/v4/logger"
	"net/http"
	"strconv"
	. "xm_shop/models"
	pb "xm_shop/proto/goods"
)

type GoodsController struct{}

func (g GoodsController) Index(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	if page == 0 {
		page = 1
	}
	pageSize := 5
	microClient := pb.NewGoodsService("goods", MicroClient)
	res, err := microClient.GetGoods(context.Background(), &pb.GetGoodsRequest{
		Page:     int64(page),
		PageSize: int32(pageSize),
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Info(res)
	c.JSON(http.StatusOK, gin.H{
		"goodsList": res.GoodsList,
	})
}
